In [24]:
using Base.Test

testing utility functions


In [170]:
include("../src/utils.jl")


Out[170]:
rand_indices (generic function with 1 method)

test sampling of random concentration parameter


In [172]:
k = 2
N = 100
alpha = 1.0

gamma_a = 1.0
gamma_b = 1.0

alpha = random_concentration_parameter!(alpha, gamma_a, gamma_b, N, k, maxiter = 10)

@test alpha < 1.0
@test alpha > 0.0

In [174]:
random_concentration_parameter(alpha, gamma_a, gamma_b, N, k, maxiter = 10)
@time random_concentration_parameter(alpha, gamma_a, gamma_b, N, k, maxiter = 10)


elapsed time: 3.1783e-5 seconds (528 bytes allocated)
Out[174]:
0.07449166710212353

In [175]:
k = [2 4]
N = [100 100]
alpha = 1.0

gamma_a = 1.0
gamma_b = 1.0

alpha = random_concentration_parameter(alpha, gamma_a, gamma_b, N, k, maxiter = 10)

@test alpha < 1.0
@test alpha > 0.0

In [177]:
random_concentration_parameter(alpha, gamma_a, gamma_b, N, k, maxiter = 10)
@time random_concentration_parameter(alpha, gamma_a, gamma_b, N, k, maxiter = 10)


elapsed time: 0.000297433 seconds (59488 bytes allocated)
Out[177]:
0.09708714626099428

test rand index function


In [179]:
p = [0.1 0.7 0.2]

pp = [0 0 0]
for j = 1:10000
    pp[rand_indices(p)] += 1
end

pp /= 10000

@test_approx_eq_eps pp[1] p[1] 0.01
@test_approx_eq_eps pp[2] p[2] 0.01
@test_approx_eq_eps pp[3] p[3] 0.01

In [180]:
for j = 1:10000
    rand_indices(p)
end

@time for j = 1:10000
    rand_indices(p)
end


elapsed time: 0.000631104 seconds (0 bytes allocated)
Out[180]:
1x3 Array{Float64,2}:
 0.0985  0.6992  0.2023